﻿using YunxSoft.Abp.LanguageManagement.Localization;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Localization;

namespace YunxSoft.Abp.LanguageManagement.Permissions;

public class LanguageManagementPermissionDefinitionProvider : PermissionDefinitionProvider
{
    public override void Define(IPermissionDefinitionContext context)
    {
        var languageManagementGroup = context.AddGroup(LanguageManagementPermissions.GroupName, L("Permission:LanguageManagement"));
        
        var languagesPermission = languageManagementGroup.AddPermission(LanguageManagementPermissions.Languages.Default, L("Permission:Languages"));
        languagesPermission.AddChild(LanguageManagementPermissions.Languages.Create, L("Permission:LanguagesCreate"));
        languagesPermission.AddChild(LanguageManagementPermissions.Languages.Update, L("Permission:LanguagesEdit"));
        languagesPermission.AddChild(LanguageManagementPermissions.Languages.Delete, L("Permission:LanguagesDelete"));
        languagesPermission.AddChild(LanguageManagementPermissions.Languages.ChangeDefault, L("Permission:LanguagesChangeDefault"));
        
        var languageTextsPermission = languageManagementGroup.AddPermission(LanguageManagementPermissions.LanguageTexts.Default, L("Permission:LanguageTexts"));
        languageTextsPermission.AddChild(LanguageManagementPermissions.LanguageTexts.Update, L("Permission:LanguageTextsEdit"));
    }

    private static LocalizableString L(string name)
    {
        return LocalizableString.Create<LanguageManagementResource>(name);
    }
}
